(function () {


    var oTextarea = document.forms[0].content;
    var $oBtn = $("#btnSubmit");
    oTextarea.onchange = function () {
        if (oTextarea.value !== "") {
            $oBtn.removeClass("disable").addClass("enable");
            document.forms[0].btn.disabled = false;
        } else {
            $oBtn.removeClass("enable").addClass("disable");
            document.forms[0].btn.disabled = true;
        }
    };
    $oBtn.on("click", function (event) {
        event.preventDefault();
        var content = document.forms[0].content.value,
            type = document.forms[0].type.value,
            phone = document.forms[0].phone.value;
        if(phone !== "") {
            if(validate(phone)) {
                $.ajax({
                    type: 'POST',
                    url: 'feedback.php',
                    // 用户提交的数据
                    data: {
                        content: content,
                        type: type,
                        phone: phone
                    },
                    // 服务器返回的内容
                    timeout: 3000,
                    success: function (data) {
                        alert(data);
                    },
                    error: function (xhr, type) {
                        alert('错误!');
                    }
                });
            } else {
                alert("输入手机号码有误");
            }

        } else {
            $.ajax({
                type: 'POST',
                url: 'feedback.php',
                // 用户提交的数据
                data: {
                    content: content,
                    type: type,
                    phone: phone
                },
                // 服务器返回的内容
                timeout: 3000,
                success: function (data) {
                    alert(data);
                },
                error: function (xhr, type) {
                    alert('错误!');
                }
            });
        }
    });

    function validate(phoneNum) {
        var reg = /^1[3|4|5|7|8][0-9]{9}$/; //验证规则
        return reg.test(phoneNum); //true
    }
})();
